package com.dm.learn_rxjava_retrofit;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;

import butterknife.Bind;
import butterknife.ButterKnife;
import rx.Observable;
import rx.Observer;

/**
 * Created by Damon.Han on 2016/12/2 0002.
 *
 * @author Damon
 */
public class Fragment1 extends Fragment {
    @Bind(R.id.result)
    TextView result;
    @Bind(R.id.fragment1)
    FrameLayout fragment1;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment1, container, false);
        ButterKnife.bind(this, view);
        testConcat();
        return view;
    }

    private void testConcat() {
        Observable<String> o1 = Observable.just("a1");
        Observable<String> o2 = Observable.just("a2");
        Observable<String> o3 = Observable.just("a3");
        Observable.concat(o2, o1, o3).subscribe(new Observer<String>() {
            @Override
            public void onCompleted() {
                Log.e("test---onCompleted ", "onCompleted");
            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onNext(String s) {
                Log.e("test---onNext ", "onNext s : " + s);
            }
        });
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }
}
